package moxl.xpath.axes;

import java.util.ArrayList;
import java.util.List;

import moxl.dom.MoxlElement;
import moxl.dom.MoxlNode;
import moxl.dom.MoxlNodeVisitor;
import moxl.xpath.parser.types.NodeTestMatcher;

public class DescendantElementCollector implements MoxlNodeVisitor
{
	private final NodeTestMatcher matcher;
	private final List<MoxlNode> list = new ArrayList<MoxlNode>();

	public DescendantElementCollector(NodeTestMatcher matcher)
	{
		this.matcher = matcher;
	}

	public void endNode(MoxlNode node)
	{
	}

	public void startNode(MoxlNode node)
	{
		if (node instanceof MoxlElement && matcher.matches(node))
		{
			list.add(node);
		}
	}

	public Iterable<MoxlNode> getNodesIterable()
	{
		return list;
	}

}
